﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;



using ProyectoFinal.Controles;



public partial class frmConsultas : System.Web.UI.Page
{
    conConsultas control;
    DataView dv;

    String strcon = "";

    protected void Page_Load(object sender, EventArgs e)
    {

        strcon = ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString;

        if (!this.IsPostBack)
        {
            strcon = ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString;

            control = new conConsultas(strcon);

            dv = new DataView(control.ObtenerPeriodo());

            DropDownList1.DataSource = dv;
            DropDownList1.DataTextField = "nombre";
            DropDownList1.DataValueField = "codigo";
            DropDownList1.DataBind();

            DropDownList2.DataSource = dv;
            DropDownList2.DataTextField = "Nombre";
            DropDownList2.DataValueField = "Codigo";
            DropDownList2.DataBind();

            CargarDatos(Convert.ToInt32(DropDownList1.SelectedItem.Value), ((Usuario)Session["ClsUsuario"]).codigo);


            //periodo = Convert.ToInt32(DropDownList2.SelectedItem.Value);
       

        }
    }

    void CargarDatos(int periodo, int alumno)
    {
        control = new conConsultas(this.strcon);

        dv = new DataView(control.ObtenerCursoPorPeriodo(periodo, alumno));
        gridCurso.DataSource = dv;
        gridCurso.DataBind();


        dv = new DataView(control.ObtenerHorarioPorPeriodo(periodo, alumno));
        gridHorario.DataSource = dv;
        gridHorario.DataBind();

        dv = new DataView(control.ObtienerNotaPorPeriodo(periodo, ((Usuario)Session["ClsUsuario"]).codigo));
        gridNotas.DataSource = dv;
        gridNotas.DataBind();

        
    }
    
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        CargarDatos(Convert.ToInt32(DropDownList1.SelectedItem.Value), ((Usuario)Session["ClsUsuario"]).codigo);
    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        CargarDatos(Convert.ToInt32(DropDownList2.SelectedItem.Value), ((Usuario)Session["ClsUsuario"]).codigo);
    }
  
}
